/*
	Simple Software Renderer (SSRenderer)
	Copyright (C) 2007 Piotr Orzechowski <piotr.orzechowski@gmail.com>

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef _SSRRENDERTARGET_H
#define _SSRRENDERTARGET_H

#include "SSRTypes.h"
#include "ISSRObject.h"
#include "SSRSurface.h"

namespace ssr
{
/**
	SSRRenderTarget is a class encapsulating a set of objects
	(i.e. surfaces and other information) needed by	SSRRenderer
	to draw graphics on. Remember that rendering target is not
	only the color buffer. Usually it consists of other useful
	buffers and objects (!).

	Think of it as a rendering destination or - canvas.
*/
class SSRRenderTarget :
    public ISSRObject
{
public:

	/**
		Static method used to create an instance of SSRRenderTarget.

		Important: CreateTarget() is the only way of creating
		an instace of SSRRenderTarget.

		When the object is no longer needed, just call
		SSR_RELEASE(ptr) with a pointer to the object.

		@param width width of the rendering target
		@param height height of the rendering target

		@return pointer to the newly created SSRRenderTarget object
	*/
	static SSRRenderTarget* CreateTarget(u32 width, u32 height);

	/**
		Locks the surface for pixel operations.

		Attempting to use pixel operations on a rendering target which
		is not locked, can cause serious trouble.
	*/
	void Lock();

	/**
		Unlocks the surface.
	*/
	void Unlock();

	/**
		@return true if the rendering target is locked, false otherwise
	*/
	bool IsLocked() const;

    /**
		Method returns a pointer to the color surface (which
		contains the main color buffer).

		@return pointer to the primary rendering surface
	*/
	SSRSurface* GetColorSurface();

	/**
		Returns width of the rendering target.

		@return width of the surface
	*/
	u32 GetWidth() const;

	/**
		Returns height of the rendering target.

		@return height of the surface
	*/
	u32 GetHeight() const;

	/**
		Returns NULL-ended string containing name of the class.
		Satisfies ISSRObject implementation.

		@return NULL-ended string containing name of the class
	*/
	const u8* ClassName()
	{
		const static u8 name[] = "SSRRenderTarget\0";
		return name;
	}

protected:

    /**
        Default constructor.
    */
	SSRRenderTarget();

	/**
		Virtual destructor.
	*/
	virtual ~SSRRenderTarget();


	/** Says whether the rendering target is currently locked or not */
	bool m_bIsLocked;

	/** Surface of the color buffer */
	SSRSurface *m_pColorSurface;

	/** Surface of the accumulation buffer */
	///@todo dodac obsluge bufora akumulacji
	SSRSurface *m_pAccumulationSurface;
};

} // namespace

#endif
